#pragma once

using namespace System;
using namespace System::IO;
using namespace NUnit::Framework;
using namespace LatoolNet;

namespace LatoolNetTest {

	[TestFixture]
	public ref class LeastSquareTest {
	public:

		[Test]
		void Test() {

			Matrix ^ a = gcnew Matrix(6, 4);
			Matrix ^ b = gcnew Matrix(6, 1);

			a[0, 0] = -0.57;
			a[0, 1] = -1.28;
			a[0, 2] = -0.39;
			a[0, 3] = 0.25;

			a[1, 0] = -1.93;
			a[1, 1] = 1.08;
			a[1, 2] = -0.31;
			a[1, 3] = -2.14;

			a[2, 0] = 2.30;
			a[2, 1] = 0.24;
			a[2, 2] = 0.40;
			a[2, 3] = -0.35;

			a[3, 0] = -1.93;
			a[3, 1] = 0.64;
			a[3, 2] = -0.66;
			a[3, 3] = 0.08;

			a[4, 0] = 0.15;
			a[4, 1] = 0.30;
			a[4, 2] = 0.15;
			a[4, 3] = -2.13;

			a[5, 0] = -0.02;
			a[5, 1] = 1.03;
			a[5, 2] = -1.43;
			a[5, 3] = 0.50;

			b[0, 0] = -2.67;
			b[1, 0] = -0.55;
			b[2, 0] = 3.34;
			b[3, 0] = -0.77;
			b[4, 0] = 0.48;
			b[5, 0] = 4.10;


			LeastSquare::Solve(a, b);

			Assert::AreEqual(1.5339, Math::Round(b[0, 0], 4), 1e-4, "Test: LeastSquare");
			Assert::AreEqual(1.8707, Math::Round(b[1, 0], 4), 1e-4, "Test: LeastSquare");
			Assert::AreEqual(-1.5241, Math::Round(b[2, 0], 4), 1e-4, "Test: LeastSquare");
			Assert::AreEqual(0.0392, Math::Round(b[3, 0], 4), 1e-4, "Test: LeastSquare");
			
		};

	};
}
